<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>已发布游记日报管理</title>
    <#include "../common/header.ftl"/>
    <#include "../common/page.ftl"/>
    <script type="text/javascript" src="/ckeditor/ckeditor.js"></script>
    <script type="text/javascript">
        $(function () {
            //切换状态--------------------------------------------------------------------------
            $('.changeBtn').click(function () {
                //获取选中的id
                var id = $(this).data('id');
                //获取该选项的id值
                var status = $(this).data('status');
                // 发送请求修改游记日报状态
                $.post('/daily/changeStatus.do',{id:id,status:status},function (data) {
                    console.log(data);
                    if(data.success){
                        $.messager.confirm("温馨提示","操作成功",function () {
                            window.location.reload();
                        })
                    }else {
                        $.messager.alert("温馨提示","操作失败");
                    }
                });
            });
            //end---------------------------------------------------------------------------------------
            //查看文章-----------------------------------------------------------------------------------
            $('.lookBtn').click(function() {
                var dailyId =  $(this).data('id');
                $.get('/daily/getDailyContentById.do',{dailyId:dailyId},function (data) {
                    console.log(data.content);
                    $('#showModal .modal-body').html(data.content);
                });
                $('#showModal').modal('show');
            });
            //end---------------------------------------------------------------------------------------
            // 富文本编辑器----------------------------------------
            var ckeditor = CKEDITOR.replace('content', {
                filebrowserBrowseUrl: '并没有图片服务器',
                filebrowserUploadUrl: '/images/upload.do'
            });
            //end-------------------------------------------------

            //推荐模态框---------------------------------------------------------------------------------------
            $('.pushBtn').click(function () {
                // //清空表单中内容
                $('#editForm')[0].reset();
                //清空表中的图片
                $('#editForm img').attr("src", "");
                //清空富文本框中内容
                ckeditor.setData("");
                var data = $(this).data('json');
                console.log(data);
                if (data) {
                    $('#editForm input[name="title"]').val(data.title);
                    $('#editForm input[name="source"]').val(data.source);
                    $('#editForm input[name="coverUrl"]').val(data.coverUrl);
                    $('#editForm img').attr("src", data.coverUrl);
                }

                // 发送请求获取内容,并回显在富文本框中
                $.get('/daily/getDailyContentById.do', {daliyId: data.id}, function (data) {
                    console.log(data);
                    ckeditor.setData(data.content);
                    $('#editModal').modal('show');
                });

                // 推荐保存操作------------------------------------------------------------------------------------
                $('.btn_submit').click(function () {
                    $('#content').html(ckeditor.getData());
                    // 插件原因,不能在循环中return false,没效果
                    var flag = false;
                    $('#editForm').ajaxSubmit({
                        beforeSubmit: function (params) {
                            $.each(params, function (index, value) {
                                // 遍历表单中所有的参数,找到type
                                if ($(value).attr("name") === "type") {
                                    // 其对应的值如果是-1说明用户没有选择推荐类型
                                    if ($(value).attr("value") == -1) {
                                        flag = true;
                                    }
                                }
                            })
                            if (flag) {
                                $.messager.alert("温馨提示", "请选择推荐类型!");
                                return false;
                            }
                        },
                        success: function (data) {
                            if (data.success) {
                                window.location.reload();
                            }
                        }
                    });
                });
                //end----------------------------------------------------------------------------
            })
        });
    </script>
    <style type="text/css">
        #showModal img {
            width: 100%;
        }
        #showModal .modal-body{
            max-height: 600px;
            overflow-y: auto;
        }
    </style>
</head>

<body>
<div class="container">
<#include "../common/top.ftl"/>
    <div class="row">
        <div class="col-sm-3">
		<#assign currentMenu = "daily_release" />
				<#include "../common/menu.ftl" />
        </div>
        <div class="col-sm-9">
            <div class="page-header">
                <h3>已发布游记日报管理</h3>
            </div>
            <div class="row">
                <!-- 提交分页的表单 -->
                <form id="searchForm" class="form-inline" method="post" action="/daily/releaseList.do">
                    <input type="hidden" name="currentPage" id="currentPage" value="1"/>
                    <div class="form-group">
                    </div>
                    <div class="form-group">
                        <label>关键字</label>
                        <input class="form-control" type="text" name="keyword" placeholder="请输入标题/昵称"  value="${(qo.keyword)!''}">
                    </div>
                    <div class="form-group">
                        <button id="query" type="button" class="btn btn-success"><i class="icon-search"></i> 查询</button>
                    </div>
                </form>
            </div>
            <div class="row">
                <table class="table">
                    <thead>
                    <tr>
                        <th>标题</th>
                        <th>封面</th>
                        <th>作者</th>
                        <th>状态</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
					<#list result.list as vo>
                    <tr>
                        <td>${vo.title!}</td>
                        <td><img src="${vo.coverUrl!}" style="width: 60px" alt=""></td>
                        <td>${vo.author.nickName!}</td>
                        <td>${vo.statusDisplay}</td>
                        <td>
                            <a href="javascript:;" class="btn btn-success changeBtn" data-id="${vo.id}" data-status="1">取消发布</a>
                            <a href="javascript:;" class="btn btn-primary lookBtn" data-id="${vo.id}">查看文章</a>
                            <a href="javascript:;" class="btn btn-success pushBtn"  data-json='${vo.jsonString}'>推荐</a>
                        </td>
                    </tr>
                    </#list>
                    </tbody>
                </table>

                <div style="text-align: center;">
                    <ul id="pagination" class="pagination"></ul>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="modal fade" id="showModal">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title">游记日报详情</h4>
            </div>
            <div class="modal-body">
            <#--游记日报内容-->
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">确定</button>
            </div>
        </div>
    </div>
</div>


<#--弹出添加或修改的模态框-->
<div class="modal fade" id="editModal">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title">编辑/添加</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/dailyCommend/saveOrUpdate.do" method="post" id="editForm"
                      enctype="multipart/form-data">
                    <input type="hidden" value="" name="id">
                    <div class="form-group" id="parentDiv">
                        <label class="col-sm-3 control-label">标题：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="title">
                        </div>
                    </div>
                    <div class="form-group" id="parentDiv">
                        <label class="col-sm-3 control-label">副标题：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="subTitle">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">封面 ：</label>
                        <div class="col-sm-6">
                            <img style="width: 250px;"/>
                            <input type="file" class="form-control" name="file">
                            <input type="hidden" class="form-control" name="coverUrl">
                        </div>
                    </div>


                    <div class="form-group" id="parentDiv">
                        <label class="col-sm-3 control-label">来源：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="source">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-3 control-label">推荐类型 ：</label>
                        <div class="col-sm-6">
                            <select id="type" name="type" class="form-control">
                                <option value="-1">请选择推荐类型</option>
                                <option value="0">正常推荐</option>
                                <option value="1">头条推荐</option>
                            </select>
                        </div>
                    </div>


                    <div class="form-group">
                        <label class="col-sm-3 control-label">优先度：</label>
                        <div class="col-sm-6">
                            <input type="number" class="form-control" name="sequence">
                        </div>
                    </div>

                    <div class="form-group">
                        <div class="col-sm-12">
                            <textarea name="commendContent.content" id="content" class="ckeditor" rows="10" cols="80">

                            </textarea>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary btn_submit">保存</button>
                <button type="button" class="btn btn-danger" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>
</div>

</body>
</html>